<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/moment.2.24.0.js"></script>
    <script src="./lib/vue2.4.4.js"></script>
    <!-- `vue-resource` 依赖于 `vue` -->
    <script src="./lib/vue-resource1.3.4.js"></script>
</head>

<body>
    <div id="app">
        <com2 v-on:func123="show"></com2>
    </div>
    <template id="tmpl">
        <div>
            <h1>这是子组件中的一个h1标签</h1>
            <input type="button" value="这是子组件中的按钮" @click="myclick">
        </div>
    </template>
    <script>
        var com2 = {
            template: '#tmpl',
            data(){
                return {
                    sonmsg: {
                        name: '大头儿子',
                        age: 6
                    }
                };
            },
            methods: {
                myclick() {
                    this.$emit('func123', JSON.stringify(this.sonmsg));
                }
            }
        };
        var vm = new Vue({
            el: '#app',
            data: {
                msg: null
            },
            methods: {
                show(arg1) {
                    console.log('调用了父组件的 show 方法', arg1);
                    this.msg = arg1;
                }
            },
            components: {
                com2
            }
        });
    </script>
</body>

</html>